<?php
define('PAGE_NEED_PRI','UPLOAD_FILE');
if(isset($_REQUEST[session_name()]))
	$_COOKIE[session_name()] = $_REQUEST[session_name()];
session_start();
include_once("main.php");
include_once("../inc/JSON.php");
include_once("blog-main-edit-function.php");

// JQuery File Upload Plugin v1.4.1 by RonnieSan - (C)2009 Ronnie Garcia
if (!empty($_FILES)) {


	$tempFile = $_FILES['Filedata']['tmp_name'];
	$file_type = substr($_FILES['Filedata']['name'], strrpos($_FILES['Filedata']['name'], "."));
	$targetPath = dirname(dirname(__FILE__)).'/upfiles/tmp/';
	//$targetPath = '/Library/WebServer/Documents/bios/upfiles/';
	$fileName = time().$file_type;
	$targetFile =  str_replace('//','/',$targetPath) . $fileName ;

	
	move_uploaded_file($tempFile,$targetFile);
	
	$response = '';
	$responsetype = isset($_REQUEST['responsetype'])?$_REQUEST['responsetype']:'';
	switch($responsetype)
	{
		case 'sizeinfo':
			list($width, $height, $type, $attr) = getimagesize($targetFile);
			$response = sprintf("{'name':'%s','w':%d,'h':%d}",$fileName,$width, $height);
		break;
		default:
		$response = $fileName;
		break;
	}
	echo $response;
}
?>